/**
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef _ARDUINO_H
#define _ARDUINO_H

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef void (*setup_t)(void);
typedef void (*loop_t)(void);

typedef struct _arduino_client {
    struct _arduino_client *next;
    setup_t setup;
    loop_t loop;
} arduino_client;

#define ARDUINO_CLIENT_DEFINE(setup, loop) \
    static void __attribute__((constructor)) _arduino_add_client_ ## setup ## _ ## loop(void) { \
        static arduino_client _client;  \
        arduino_add(&_client, setup, loop); \
    }

void arduino_add(arduino_client *client, setup_t setup, loop_t loop);
void arduino_setup(void);
void arduino_loop(void);

#ifdef __cplusplus
}
#endif

#endif
